/*
 * Created by JFormDesigner on Fri Nov 02 02:41:04 CST 2018
 */

package cn.xo68.ide.plugin.ui.form;

import cn.xo68.ide.plugin.common.GuiUtils;
import cn.xo68.ide.plugin.common.domain.ProductInfo;
import cn.xo68.ide.plugin.common.resources.Messages;
import cn.xo68.ide.plugin.service.AboutUsService;
import icons.WxIcons;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

/**
 * @author wyy
 */
public class AboutUsDialog extends JDialog {

    private static Logger logger = LoggerFactory.getLogger(AboutUsDialog.class);

    public static void open(){

        //logger.info(PluginConstants.getPluginDescriptor().getName());

        Window window= GuiUtils.getIdeaWindow();
        AboutUsDialog aboutDialog=new AboutUsDialog((Frame) window);
        aboutDialog.setIconImage(WxIcons.loadImage(WxIcons.PATH_ABOUT));
        GuiUtils.openDialog(aboutDialog,Messages.DIALOG_ABOUT_TITLE,420,380);

    }

    private ProductInfo productInfo;
    private ButtonModel okButtomModel;



    public AboutUsDialog(Frame owner) {
        super(owner);
        initComponents();
        initData();
    }

    public AboutUsDialog(Dialog owner) {
        super(owner);
        initComponents();
        initData();
    }

    protected void initData(){

        okButton.setText(Messages.DIALOG_ABOUT_BTN_SITE_TEXT);
        cancelButton.setText(Messages.DIALOG_ABOUT_BTN_CLOSE_TEXT);
        taRemark.setText(Messages.DIALOG_ABOUT_REMARK);

        ProductInfo productInfo = AboutUsService.getInstance().getProductInfo();
        lb_name_val.setText(productInfo.getName());
        lbAuthorValue.setText(productInfo.getAuthor());
        lbVersionValue.setText(productInfo.getVersion());
        lbPluginIdValue.setText(productInfo.getPluginId());

        lbHeader.setIcon(WxIcons.LOGO);

    }

    private void cancelButtonActionPerformed(ActionEvent e) {
        // TODO add your code here
        dispose();
    }

    private void okButtonActionPerformed(ActionEvent e) {
        try {
            URI uri = new URI(Messages.DIALOG_ABOUT_BTN_SITE_URI);
            Desktop.getDesktop().browse(uri);
        } catch (URISyntaxException e1) {
            logger.error("路径异常",e1);
        } catch (IOException e1) {
            logger.error("io异常",e1);
        }

        dispose();
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        dialogPane = new JPanel();
        contentPanel = new JPanel();
        lbHeader = new JLabel();
        panel_body = new JPanel();
        lb_name = new JLabel();
        lb_name_val = new JLabel();
        lbAuthor = new JLabel();
        lbAuthorValue = new JLabel();
        lbVersion = new JLabel();
        lbVersionValue = new JLabel();
        lbPluginId = new JLabel();
        lbPluginIdValue = new JLabel();
        scrollPane1 = new JScrollPane();
        taRemark = new JTextArea();
        buttonBar = new JPanel();
        okButton = new JButton();
        cancelButton = new JButton();

        //======== this ========
        Container contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());

        //======== dialogPane ========
        {
            dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
            dialogPane.setLayout(new BorderLayout());

            //======== contentPanel ========
            {
                contentPanel.setLayout(new GridBagLayout());
                ((GridBagLayout)contentPanel.getLayout()).columnWidths = new int[] {400, 0};
                ((GridBagLayout)contentPanel.getLayout()).rowHeights = new int[] {80, 240, 0};
                ((GridBagLayout)contentPanel.getLayout()).columnWeights = new double[] {1.0, 1.0E-4};
                ((GridBagLayout)contentPanel.getLayout()).rowWeights = new double[] {0.0, 1.0, 1.0E-4};
                contentPanel.add(lbHeader, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
                    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                    new Insets(0, 0, 0, 0), 0, 0));

                //======== panel_body ========
                {
                    panel_body.setLayout(new GridBagLayout());
                    ((GridBagLayout)panel_body.getLayout()).columnWidths = new int[] {150, 0, 0};
                    ((GridBagLayout)panel_body.getLayout()).rowHeights = new int[] {0, 0, 0, 9, 64, 0};
                    ((GridBagLayout)panel_body.getLayout()).columnWeights = new double[] {0.0, 1.0, 1.0E-4};
                    ((GridBagLayout)panel_body.getLayout()).rowWeights = new double[] {1.0, 1.0, 1.0, 1.0, 0.0, 1.0E-4};

                    //---- lb_name ----
                    lb_name.setText("\u63d2\u4ef6\u540d\u79f0\uff1a");
                    panel_body.add(lb_name, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
                        GridBagConstraints.EAST, GridBagConstraints.VERTICAL,
                        new Insets(0, 0, 3, 5), 0, 0));

                    //---- lb_name_val ----
                    lb_name_val.setText("lb_name_val");
                    panel_body.add(lb_name_val, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                        new Insets(0, 0, 3, 0), 0, 0));

                    //---- lbAuthor ----
                    lbAuthor.setText("\u4f5c\u8005\uff1a");
                    panel_body.add(lbAuthor, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
                        GridBagConstraints.EAST, GridBagConstraints.VERTICAL,
                        new Insets(0, 0, 3, 5), 0, 0));

                    //---- lbAuthorValue ----
                    lbAuthorValue.setText("lbAuthorValue");
                    panel_body.add(lbAuthorValue, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                        new Insets(0, 0, 3, 0), 0, 0));

                    //---- lbVersion ----
                    lbVersion.setText("\u63d2\u4ef6\u7248\u672c\uff1a");
                    panel_body.add(lbVersion, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
                        GridBagConstraints.EAST, GridBagConstraints.VERTICAL,
                        new Insets(0, 0, 3, 5), 0, 0));

                    //---- lbVersionValue ----
                    lbVersionValue.setText("lbVersionValue");
                    panel_body.add(lbVersionValue, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                        new Insets(0, 0, 3, 0), 0, 0));

                    //---- lbPluginId ----
                    lbPluginId.setText("\u63d2\u4ef6ID\uff1a");
                    panel_body.add(lbPluginId, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0,
                        GridBagConstraints.EAST, GridBagConstraints.VERTICAL,
                        new Insets(0, 0, 3, 5), 0, 0));

                    //---- lbPluginIdValue ----
                    lbPluginIdValue.setText("lbPluginIdValue");
                    panel_body.add(lbPluginIdValue, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                        new Insets(0, 0, 3, 0), 0, 0));

                    //======== scrollPane1 ========
                    {
                        scrollPane1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

                        //---- taRemark ----
                        taRemark.setLineWrap(true);
                        taRemark.setWrapStyleWord(true);
                        taRemark.setEditable(false);
                        scrollPane1.setViewportView(taRemark);
                    }
                    panel_body.add(scrollPane1, new GridBagConstraints(0, 4, 2, 1, 0.0, 0.0,
                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                        new Insets(0, 0, 0, 0), 0, 0));
                }
                contentPanel.add(panel_body, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
                    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                    new Insets(0, 0, 0, 0), 0, 0));
            }
            dialogPane.add(contentPanel, BorderLayout.CENTER);

            //======== buttonBar ========
            {
                buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
                buttonBar.setLayout(new GridBagLayout());
                ((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80};
                ((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0};

                //---- okButton ----
                okButton.setText("OK");
                okButton.addActionListener(e -> okButtonActionPerformed(e));
                buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
                    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                    new Insets(0, 0, 0, 5), 0, 0));

                //---- cancelButton ----
                cancelButton.setText("Cancel");
                cancelButton.addActionListener(e -> cancelButtonActionPerformed(e));
                buttonBar.add(cancelButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
                    GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                    new Insets(0, 0, 0, 0), 0, 0));
            }
            dialogPane.add(buttonBar, BorderLayout.SOUTH);
        }
        contentPane.add(dialogPane, BorderLayout.CENTER);
        setSize(415, 365);
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JPanel dialogPane;
    private JPanel contentPanel;
    private JLabel lbHeader;
    private JPanel panel_body;
    private JLabel lb_name;
    private JLabel lb_name_val;
    private JLabel lbAuthor;
    private JLabel lbAuthorValue;
    private JLabel lbVersion;
    private JLabel lbVersionValue;
    private JLabel lbPluginId;
    private JLabel lbPluginIdValue;
    private JScrollPane scrollPane1;
    private JTextArea taRemark;
    private JPanel buttonBar;
    private JButton okButton;
    private JButton cancelButton;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
